#include <stdio.h>

unsigned int uipow(unsigned int base, unsigned int exp)
{
	unsigned int i, ret = 1;
	if (0 < exp) {
		for (i=0; i<exp; i++) {
			ret = ret * base;
		}
	}
	
	return ret;
}

int main(int argc, char *argv[])
{
	unsigned int lcnt, case_num = 1;
	unsigned int n, k, power;
	
	scanf("%u", &lcnt);
	while (lcnt--) {
		scanf("%u", &n);
		scanf("%u", &k);

		power = uipow(2, n);

		printf("Case #%u: ", case_num);
		if (0 == (k+1) % power) {
			printf("ON");
		} else {
			printf("OFF");
		}
		printf("\n");

		case_num++;
	}

	return 0;
}
